
define(function(require, exports, module) {
    var component = {};
    component.vue = function(params) {
        var vm = new Vue({
        el: '#component_bindphone_content',
        data: {
            sendingcode:0,
        },
        created: function() {
            
        },
         mounted: function() {
              if (this.mounted == 1) {
                        return;
                    }
             
        },
        methods: {

        dobindphone:function(){
          var phone = $("#component_bindphone_content #phone").val();
          var code = $("#component_bindphone_content #code").val();
          app.post("apiv2/user/bindPhone",{phone:phone,code:code},function(res){
             if(res.code!=200){
                app.alert(res.msg);
                return ;
             }
            var userInfo = app.getUserInfo();
            userInfo.token= res.data.token;
            userInfo.user_id= res.data.user_id;
            app.setUserInfo(userInfo);
            params.success?params.success():'';
          });
        },
        
        cancel:function(){
          window.history.back();
        },
        getCode:function(){
  
          var i =60;
          var that = this;
          // var that = $("#codeBnt");
          if(this.sendingcode==1){
             return ;
          }
          this.sendingcode = 1;
         //验证码倒计时
          $("#codeBnt").text("重新获取("+i+"s)");
          var t = setInterval(function(){
             i--;
             $("#codeBnt").text("重新获取("+i+"s)");
             if(i===0){
                clearInterval(t);
                $("#codeBnt").text('获取验证码');
                that.sendingcode =0;
             }
            },1000);
          
          var phone = $("#component_bindphone_content #phone").val();

          //加密
         
          app.get("apiv2/user/getPhoneCode",{phone:phone},function(res){
             if(res.code!=200){
                app.alert(res.msg);
                that.sendingcode = 0;
                clearInterval(t);
                $("#codeBnt").text('获取验证码');
               return ;
             }
          });

         },

        }
        });
        return vm;
    };
    
  module.exports = component;

});